public class LC1894M {
    public int chalkReplacer(int[] chalk, int k) {
        int sum=0;
        int n=chalk.length;
        for (int j : chalk) {
            sum += j;
            if (sum>k)
                break;
        }
        k=k%sum;
        int index=0;
        while (k>=0){
            k=k-chalk[index];
            index++;
        }
        return index-1;
    }
}
